/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            housekeepingDispatchManageInfo: {
                pools: [],
                total: 0,
                records: 1,
                moreCondition: false,
                states: [],
                conditions: {
                    cartId: '',
                    applyName: '',
                    applyTel: '',
                    repairType: '',
                    roomId: '',
                    roomName: '',
                    ownerId: '',
                    state: ''
                }
            }
        },
        _initMethod: function () {
            $that._listHousekeepingPools(DEFAULT_PAGE, DEFAULT_ROWS);
            //$that._validateParam();
            //与字典表关联
            vc.getDict('housekeeping_serv_pool', "state", function (_data) {
                $that.housekeepingDispatchManageInfo.states = _data;
            });
        },
        _initEvent: function () {
            vc.on('housekeepingDispatchManage', 'listHousekeepingPool', function (_param) {
                location.reload();
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listHousekeepingPools(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listHousekeepingPools: function (_page, _rows) {
                $that.housekeepingDispatchManageInfo.conditions.page = _page;
                $that.housekeepingDispatchManageInfo.conditions.row = _rows;
                $that.housekeepingDispatchManageInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                var param = {
                    params: $that.housekeepingDispatchManageInfo.conditions
                };
                param.params.cartId = param.params.cartId.trim();
                param.params.applyName = param.params.applyName.trim();
                param.params.applyTel = param.params.applyTel.trim();
                param.params.state = param.params.state.trim();
                //发送get请求
                vc.http.apiGet('/housekeepingServPool/queryStaffServ',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.housekeepingDispatchManageInfo.total = _json.total;
                        $that.housekeepingDispatchManageInfo.records = _json.records;
                        $that.housekeepingDispatchManageInfo.pools = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.housekeepingDispatchManageInfo.records,
                            dataCount: $that.housekeepingDispatchManageInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            //查询
            _queryHousekeepingPoolMethod: function () {
                $that._listHousekeepingPools(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetHousekeepingPoolMethod: function () {
                $that.housekeepingDispatchManageInfo.conditions.cartId = "";
                $that.housekeepingDispatchManageInfo.conditions.applyName = "";
                $that.housekeepingDispatchManageInfo.conditions.applyTel = "";
                $that.housekeepingDispatchManageInfo.conditions.state = "";
                $that._listHousekeepingPools(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //办结
            _openFinishRepair: function (_pool) {
                // vc.emit('finishRepair', 'openFinishRepairModal', _pool);
                vc.jumpToPage('/#/pages/goods/finishHousekeepingPool?poolId=' + _pool.poolId + "&servId=" + _pool.servId);
            },
            _openDispatchRepairDetail: function (_pool) {
                //vc.emit('poolDetail','openHousekeepingPoolDetailModal',_pool);
                vc.jumpToPage('/#/pages/goods/poolDetail?repairId=' + _pool.repairId);
            },
            _moreCondition: function () {
                if ($that.housekeepingDispatchManageInfo.moreCondition) {
                    $that.housekeepingDispatchManageInfo.moreCondition = false;
                } else {
                    $that.housekeepingDispatchManageInfo.moreCondition = true;
                }
            },
            _openDispatchRepairModel: function (_pool) {
                _pool.action = "TRANSFER";
                vc.emit('dispatchHousekeeping', 'openDispatchHousekeepingModal', _pool);
            },
            _openBackRepairModel: function (_pool) {
                _pool.action = "BACK";
                vc.emit('dispatchHousekeeping', 'openDispatchHousekeepingModal', _pool);
            },
            //回访
            _openAppraiseRepair: function (_pool) {
                vc.emit('appraiseRepair', 'openAppraiseRepairModal', _pool);
            },
            _openDetail: function (_pool) {
                vc.jumpToPage('/#/pages/goods/housekeepingServDetail?poolId=' + _pool.poolId + "&servId=" + _pool.servId)
            },
            _openReleaseHousekeepingServPoolUserModal: function (_pool) {
                let _data = {
                    shopId: vc.getCurrentCommunity().shopId,
                    poolId: _pool.poolId
                };
                vc.http.apiPost(
                    '/housekeepingServPoolUser/releaseRepair',
                    JSON.stringify(_data),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            vc.emit('pagination', 'page_event', {});
                            vc.toast("操作成功");
                            return;
                        } else {
                            vc.toast(_json.msg);
                        }
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.toast(errInfo);
                    });
            }
        }
    });
})(window.vc);
